package com.eastfair.pay.exceptioncode;

import com.eastfair.annotation.base.LanguageTypeEnum;
import com.eastfair.core.context.ContextUtil;
import com.eastfair.core.exception.code.BaseExceptionCode;

/**
 * 支付系统异常code定义
 * AABBBCCC   AA(18)  系统编号   BBB 模块    CCC 具体异常
 */
public enum PayExceptionCode implements BaseExceptionCode {

    /**
     * 认领模块 000
     */
    ALREADY_COLLECT(18000000, "已经认领不可操作！", ""),
    PAYMENT_PLAN_EXCEED_COLLECT(18000001, "认款金额与计划付款金额不符，请调整认领金额！", ""),
    PAYMENT_RECORD_EXCEED_COLLECT(18000002, "超出付款记录金额，请调整认领金额！", ""),
    UNKNOWEN_COLLECT_TYPE(18000003, "未知认领类型！", ""),
    ALREADY_INVOICED(18000004, "合同已开票，不可取消认款！", ""),
    ORDER_EXCEED_COLLECT(18000001, "认款金额与订单金额不符，请调整认领金额！", ""),

    /**
     * 合同模块001
     */
    CONTRACT_PLAN_AMOUNT_NOT_EQ(18001000, "合同金额和计划金额不相等", ""),
    CONTRACT_HAS_COLLECTED(18001001, "合同已有认款记录不可修改", ""),
    CONTRACT_PAYMENT_PLAN_ISNULL(18001002, "合同付款计划为空", ""),
    CONTRACT_PAYMENT_PLAN_UPDATE_ERROR(18001003, "期号: %1$s 已有认款记录更新失败！", ""),
    CONTRACT_NOT_EXTIS(18001004, "合同不存在！", ""),

    /**
     * 付款计划 002
     */

    /**
     * 退款管理 003
     */
    SETTLEMEN_DOCUMENT_DOES_NOT_EXIST(18003000, "该结算单不存在", "settlement document does not exist"),
    ZERO_REFUND_NOT_ACCEPT(1803001, "退款金额未被接受", ""),
    APPLY_REFUND_DOES_NOT_EXIST(1803002, "退款申请不存在", ""),
    APPLY_REFUND_DOES_NOT_EXAMINE(1803003, "退款申请未审核", ""),
    ORDER_REFUNDED(18003004, "订单已退款，请勿重复退款", ""),
    ORDER_UNPAY(18003005, "订单未付款,不能申请退款", ""),
    REFUND_AMOUNT_GT(18003006, "申请退款金额大于可退金额", ""),
    ORDER_CANCEL(18003007, "订单已取消，不能申请退款", ""),
    ORDER_REFUNDING(18003008, "订单退款中，请勿重复退款", ""),
    /**
     * 结算管理 004
     */
//    SETTLEMEN_DOCUMENT_DOES_NOT_EXIST(18003000,"该结算单不存在","settlement document does not exist"),

    /**
     * 发票管理 005
     */
    INVOICE_DOES_NOT_EXIST(18005000, "该发票记录不存在", "invoice does not exist"),

    /**
     * 商户&商户系统管理 006
     */
    MERCHANT_IS_USED(18006000, "该商户已被引用不可删除", "merchant is used!"),

    /**
     * 交易订单 007
     */

    PAYEE_IS_EMPTY(18007000, "收款单位为空", "payee is empty"),

    FINANCIAL_ACCOUNT_DOES_NOT_EXIST(18007001, "请到财务系统配置账号", "please configure your account in the financial system"),

    TRANSACTION_ORDER_NOT_EXIST(18007002, "交易订单不存在", "Transaction order does not exist"),

    TRANSACTION_ORDER_NOT_PAY(18007003, "支付状态不是未支付或支付中，不能发起支付", ""),

    PAY_TYPE_IS_EMPTY(18007004, "支付方式为空", "payee is empty"),

    AMOUNT_ERROR(18007005, "实付金额与应支付金额不匹配", ""),

    TRANSACTION_ORDER_HAS_PAY(18007006, "支付状态已经是已支付", ""),

    NO_PAYMENT_REQUIRED(18007007, "金额未0，无需支付", ""),


    ;
    private final int code;
    //中文消息
    private String msg;
    //英文消息
    private String enMsg;

    PayExceptionCode(int code, String msg, String enMsg) {
        this.code = code;
        this.msg = msg;
        this.enMsg = enMsg;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        //中英文切换
        if (LanguageTypeEnum.CN.name().equals(ContextUtil.getLanguageType())) {
            //中文
            return msg;
        } else if (LanguageTypeEnum.EN.name().equals(ContextUtil.getLanguageType())) {
            //英文
            return enMsg;
        }
        return msg;
    }


    public PayExceptionCode build(String msg, Object... param) {
        this.msg = String.format(msg, param);
        return this;
    }

    public PayExceptionCode param(Object... param) {
        msg = String.format(msg, param);
        return this;
    }


}
